package it.asvp.asvp_portal.data.entity.news;

import it.asvp.asvp_portal.data.entity.domain.BaseEntity;
import it.asvp.asvp_portal.data.entity.domain.File;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@SuppressWarnings("serial")
@Entity
@Table(name = "news_picture", catalog = "asvp_db", uniqueConstraints = @UniqueConstraint(columnNames = { "id_news", "id_picture" }))
public class NewsPicture extends BaseEntity {

  @ManyToOne(fetch = FetchType.EAGER)
  @JoinColumn(name = "id_news", nullable = false)
  private News news;

  @ManyToOne(fetch = FetchType.EAGER)
  @JoinColumn(name = "id_picture", nullable = false)
  @Cascade({ CascadeType.ALL })
  private File file;

  public NewsPicture() {
  }

  public NewsPicture(News news, File file) {
    this.news = news;
    this.file = file;
  }

  public News getNews() {
    return this.news;
  }

  public void setNews(News news) {
    this.news = news;
  }

  public File getFile() {
    return this.file;
  }

  public void setFile(File file) {
    this.file = file;
  }

}
